<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.w3.org/1999/xhtml">

<head>
    <th:block th:include="common/common_head :: commonHeader('消息设置')"/>
</head>

<body class="gray-bg">

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="tabs-container">
                <ul class="nav nav-tabs">
                    <li class="active"><a data-toggle="tab" href="#tab-1" class="grid_tab" aria-expanded="true">内容设置</a>
                    </li>
                    <!--<li class=""><a data-toggle="tab" href="#tab-2" class="grid_tab" aria-expanded="false">签名设置</a>-->
                    <!--</li>-->
                </ul>
                <div class="tab-content">
                    <div id="tab-1" class="tab-pane active">
                        <div class="panel-body jqgrid_box">
                            <div class="row">
                                <form id="salesmanForm" th:action="@{/notice/noticemessage/list/sales}" class="form-inline"></form>
                                <form id="customerForm" th:action="@{/notice/noticemessage/list/customer}" class="form-inline"></form>
                                <form id="auntForm" th:action="@{/notice/noticemessage/list/aunt}" class="form-inline"></form>
                            </div>
                            <div class="ibox-title">
                                <h5>发送给业务员</h5>
                            </div>
                            <table id="salesman" class="table_list">
                            </table>
                            <div class="ibox-title">
                                <h5>发送给客户</h5>
                            </div>
                            <table id="customer" class="table_list">
                            </table>
                            <div class="ibox-title">
                                <h5>发送给阿姨</h5>
                            </div>
                            <table id="aunt" class="table_list">
                            </table>
                        </div>
                    </div>
                    <!--<div id="tab-2" class="tab-pane">-->
                        <!--<div class="panel-body jqgrid_box">-->
                            <!--<div class="ibox-title">-->
                                <!--<h5>业绩总览</h5>-->
                            <!--</div>-->
                            <!--<table id="member" class="table_list">-->
                            <!--</table>-->
                            <!--<div id="memberPager"></div>-->
                        <!--</div>-->
                    <!--</div>-->
                </div>
            </div>
        </div>
    </div>
</div>
<!--引入公共js-->
<div th:include="common/onload_js :: onloadJS"></div>
<!-- Page-Level Scripts -->
<script type="text/javascript">
    var tab_width = $("#tabs div.ui-tabs-panel:not(.ui-tabs-hide)").width();
    $('.grid_tab').on('shown.bs.tab',function(){
        $($(this).attr('href')).find('.table_list').jqGrid('setGridWidth',$($(this).attr('href')).find('.jqgrid_box').width());
    });

    var salesmanSearcher = Searcher.create('#salesman',
        [
            {name: 'id', hidden: true},
            {label: "业务场景", name: "scene", index: "scene", width:20, sortable: false,
            },
            {
                label: "内容", name: "content", index: "content",width:100, sortable: false,
            },
            {
                label: "发送方式", name: "mode", index: "mode",sortable: false,width:50,
                formatter: function (cellvalue, options, row) {
                    //console.log(cellvalue);
                    //console.log(options)
                    var step = "   ";
                    if (cellvalue == 1){
                        if (row.msgstate == 1){
                            var msgSend = "<input type='checkbox' name='msg' checked='checked' onclick='msgSend( " + row.id +
                                ")'> 短信</input>";
                            return msgSend  ;
                        } else {
                            var msgSend = "<input type='checkbox' name='msg' onclick='msgSend( " + row.id +
                                ")'>短信</input>";
                            return msgSend  ;
                        }

                    } else if (cellvalue == 2) {
                        if (row.rmdstate == 1){
                            var rmdSend = "<input type='checkbox' name='rmd' checked='checked' onclick='rmdSend( " + row.id +
                                ")'> 浏览器提醒</input>";
                            return rmdSend ;
                        } else {
                            var rmdSend = "<input type='checkbox' name='rmd' onclick='rmdSend( " + row.id +
                                ")'>浏览器提醒</input>";
                            return rmdSend  ;
                        }
                    } else if (cellvalue == 3) {
                        if (row.rmdstate == 1 && row.msgstate == 1){
                            var msgSend = "<input type='checkbox' name='msg' checked='checked' onclick='msgSend( " + row.id +
                                ")'>短信</input>";
                            var rmdSend = "<input type='checkbox' name='rmd' checked='checked' onclick='rmdSend( " + row.id +
                                ")'>浏览器提醒</input>";
                            return msgSend + step + rmdSend ;
                        } else if (row.rmdstate == 0 && row.msgstate == 0) {
                            var msgSend = "<input type='checkbox' name='msg' onclick='msgSend( " + row.id +
                                ")'>短信</input>";
                            var rmdSend = "<input type='checkbox' name='rmd' onclick='rmdSend( " + row.id +
                                ")'>浏览器提醒</input>";
                            return msgSend + step + rmdSend ;
                        } else if (row.msgstate == 1 && row.rmdstate == 0 ){
                            var msgSend = "<input type='checkbox' name='msg' checked='checked' onclick='msgSend( " + row.id +
                                ")'>短信</input>";
                            var rmdSend = "<input type='checkbox' name='rmd' onclick='rmdSend( " + row.id +
                                ")'>浏览器提醒</input>";
                            return msgSend + step + rmdSend ;
                        } else if (row.msgstate == 0 && row.rmdstate == 1) {
                            var msgSend = "<input type='checkbox' name='msg' onclick='msgSend( " + row.id +
                                ")'>短信</input>";
                            var rmdSend = "<input type='checkbox' name='rmd' checked='checked' onclick='rmdSend( " + row.id +
                                ")'>浏览器提醒</input>";
                            return msgSend + step + rmdSend ;
                        }

                    }
                }
            }
        ],
        {
            rownumbers: false, multiselect: false,rowNum: -1
        }
    );

    var customerSearcher = Searcher.create('#customer',
        [
            {name: 'id', hidden: true},
            {label: "业务场景", name: "scene", index: "scene", width:20, sortable: false,
            },
            {
                label: "内容", name: "content", index: "content",width:100, sortable: false,
            },
            {
                label: "发送方式", name: "mode", index: "mode",sortable: false,width:50,
                formatter: function (cellvalue, options, row) {
                    //console.log(cellvalue);
                    //console.log(options)
                    console.log(row);
                    var step = "   ";
                    if (cellvalue == 1){
                        if (row.msgstate == 1){
                            var msgSend = "<input type='checkbox' name='msg' checked='checked' onclick='msgSend( " + row.id +
                                ")'> 短信</input>";
                            return msgSend  ;
                        } else {
                            var msgSend = "<input type='checkbox' name='msg' onclick='msgSend( " + row.id +
                                ")'>短信</input>";
                            return msgSend  ;
                        }

                    } else if (cellvalue == 2) {
                        if (row.rmdstate == 1){
                            var rmdSend = "<input type='checkbox' name='rmd' checked='checked' onclick='rmdSend( " + row.id +
                                ")'> 浏览器提醒</input>";
                            return rmdSend ;
                        } else {
                            var rmdSend = "<input type='checkbox' name='rmd' onclick='rmdSend( " + row.id +
                                ")'>浏览器提醒</input>";
                            return rmdSend  ;
                        }
                    } else if (cellvalue == 3) {
                        if (row.rmdstate == 1 && row.msgstate == 1){
                            var msgSend = "<input type='checkbox' name='msg' checked='checked' onclick='msgSend( " + row.id +
                                ")'>短信</input>";
                            var rmdSend = "<input type='checkbox' name='rmd' checked='checked' onclick='rmdSend( " + row.id +
                                ")'>浏览器提醒</input>";
                            return msgSend + step + rmdSend ;
                        } else if (row.rmdstate == 0 && row.msgstate == 0) {
                            var msgSend = "<input type='checkbox' name='msg' onclick='msgSend( " + row.id +
                                ")'>短信</input>";
                            var rmdSend = "<input type='checkbox' name='rmd' onclick='rmdSend( " + row.id +
                                ")'>浏览器提醒</input>";
                            return msgSend + step + rmdSend ;
                        } else if (row.msgstate == 1 && row.rmdstate == 0 ){
                            var msgSend = "<input type='checkbox' name='msg' checked='checked' onclick='msgSend( " + row.id +
                                ")'>短信</input>";
                            var rmdSend = "<input type='checkbox' name='rmd' onclick='rmdSend( " + row.id +
                                ")'>浏览器提醒</input>";
                            return msgSend + step + rmdSend ;
                        } else if (row.msgstate == 0 && row.rmdstate == 1) {
                            var msgSend = "<input type='checkbox' name='msg' onclick='msgSend( " + row.id +
                                ")'>短信</input>";
                            var rmdSend = "<input type='checkbox' name='rmd' checked='checked' onclick='rmdSend( " + row.id +
                                ")'>浏览器提醒</input>";
                            return msgSend + step + rmdSend ;
                        }

                    }
                }
            }
        ],
        {
            rownumbers: false, multiselect: false,rowNum: -1
        }
    );
    var auntSearcher = Searcher.create('#aunt',
        [
            {name: 'id', hidden: true},
            {label: "业务场景", name: "scene", index: "scene", width:20, sortable: false,

            },
            {
                label: "内容", name: "content", index: "content",width:100, sortable: false,
            },
            {
                label: "发送方式", name: "mode", index: "mode",sortable: false,width:50,
                formatter: function (cellvalue, options, row) {
                    //console.log(cellvalue);
                    //console.log(options)
                    console.log(row);
                    var step = "   ";
                    if (cellvalue == 1){
                        if (row.msgstate == 1){
                            var msgSend = "<input type='checkbox' name='msg' checked='checked' onclick='msgSend( " + row.id +
                                ")'> 短信</input>";
                            return msgSend  ;
                        } else {
                            var msgSend = "<input type='checkbox' name='msg' onclick='msgSend( " + row.id +
                                ")'>短信</input>";
                            return msgSend  ;
                        }

                    } else if (cellvalue == 2) {
                        if (row.rmdstate == 1){
                            var rmdSend = "<input type='checkbox' name='rmd' checked='checked' onclick='rmdSend( " + row.id +
                                ")'> 浏览器提醒</input>";
                            return rmdSend ;
                        } else {
                            var rmdSend = "<input type='checkbox' name='rmd' onclick='rmdSend( " + row.id +
                                ")'>浏览器提醒</input>";
                            return rmdSend  ;
                        }
                    } else if (cellvalue == 3) {
                        if (row.rmdstate == 1 && row.msgstate == 1){
                            var msgSend = "<input type='checkbox' name='msg' checked='checked' onclick='msgSend( " + row.id +
                                ")'>短信</input>";
                            var rmdSend = "<input type='checkbox' name='rmd' checked='checked' onclick='rmdSend( " + row.id +
                                ")'>浏览器提醒</input>";
                            return msgSend + step + rmdSend ;
                        } else if (row.rmdstate == 0 && row.msgstate == 0) {
                            var msgSend = "<input type='checkbox' name='msg' onclick='msgSend( " + row.id +
                                ")'>短信</input>";
                            var rmdSend = "<input type='checkbox' name='rmd' onclick='rmdSend( " + row.id +
                                ")'>浏览器提醒</input>";
                            return msgSend + step + rmdSend ;
                        } else if (row.msgstate == 1 && row.rmdstate == 0 ){
                            var msgSend = "<input type='checkbox' name='msg' checked='checked' onclick='msgSend( " + row.id +
                                ")'>短信</input>";
                            var rmdSend = "<input type='checkbox' name='rmd' onclick='rmdSend( " + row.id +
                                ")'>浏览器提醒</input>";
                            return msgSend + step + rmdSend ;
                        } else if (row.msgstate == 0 && row.rmdstate == 1) {
                            var msgSend = "<input type='checkbox' name='msg' onclick='msgSend( " + row.id +
                                ")'>短信</input>";
                            var rmdSend = "<input type='checkbox' name='rmd' checked='checked' onclick='rmdSend( " + row.id +
                                ")'>浏览器提醒</input>";
                            return msgSend + step + rmdSend ;
                        }

                    }
                }
            }
        ],
        {
            rownumbers: false, multiselect: false,rowNum: -1
        }
    );

    function msgSend(id) {
        Dialog.confirm('确定修改？', function(index){
            Page.ajaxPOST(ctxPath + "/notice/noticemessage/update/msgState",{id:id}, function (res) {
                Dialog.msg("操作成功", function () {
                    formSearch()
                });
            });
        });
    }

    function rmdSend(id) {
        Dialog.confirm('确定修改？', function(index){
            Page.ajaxPOST(ctxPath + "/notice/noticemessage/update/rmdState",{id:id}, function (res) {
                Dialog.msg("操作成功", function () {
                    formSearch()
                });
            });
        });
    }

    function formSearch() {
        salesmanSearcher.query($('#salesmanForm'));
        customerSearcher.query($('#customerForm'));
        auntSearcher.query($('#auntForm'));
    }
</script>
</body>
</html>